<?php

/**
 * Created by PhpStorm.
 * Author: ls
 * Time: 2023/10/18 11:34
 * Desc: 红包模型
 */
class Model_Api_V2_Envelope
{
    /**
     * 允许红包使用的产品
     * @var array
     */
    private $module_name_arr = null;

    /**
     * 红包使用的model名称字符串
     * @param $type_ids
     * @return string|void
     */
    public function get_envelope_module_title($type_ids)
    {
        $this->get_module_name_arr();

        if(!$type_ids){
            return '';
        }
        $type_ids = explode(',', $type_ids);
        $data = array();
        foreach ($type_ids as $type_id) {
            if (isset($this->module_name_arr[$type_id])) {
                $data[] = $this->module_name_arr[$type_id];
            }
        }
        return implode(',', $data);
    }


    /**
     * 获取可使用红包的model的name
     * @return array
     */
    private function get_module_name_arr()
    {
        if ($this->module_name_arr == null) {
            $models                = DB::select('id', 'modulename')
                ->from('model')
                ->where('is_envelope', '=', 1)
                ->where('isopen', '=', 1)
                ->execute()
                ->as_array('id', 'modulename');
            $this->module_name_arr = $models;
        }

        return $this->module_name_arr;
    }
}